<?php

/**
 * Validate Deposit
 */
class Deposit extends CFormModel
{
	public $type;
	public $amount_transfer;
	public $you_need_have;
	public $amount_receive;
	public $code_deposit;
	public $verifyCode;

	public function rules()
	{
		return array(
			array('amount_transfer', 'required', 'message' => Yii::t('main', 'enter_amount_transfer')),
			array('amount_transfer', 'checkAmountTransfer'),
			array('code_deposit', 'required', 'message' => Yii::t('main', 'enter_code_deposit')),
			array('code_deposit', 'validateCode'),
			array('verifyCode', 'application.validators.CaptchaAjax'),
		);
	}
	public function attributeLabels()
	{
		return array(
			'verifyCode'=> Yii::t('lbl', '0008', array()),
		);
	}
	public function validateCode($attribute, $object) {
		if(!empty($this->code_deposit)) {
			$modelUser = User::model()->findByAttributes(array('code'=>$this->code_deposit));
			if(!is_object($modelUser)) {
				$this->addError($attribute, Yii::t('main', 'code_not_exist'));
			}
		}
	}
	public function checkAmountTransfer($attribute, $object) {
		if(in_array($this->type, array('wmz', 'pm', 'bk', 'nl'))){
			$min = Setting::getValueSetting('deposit', $this->type);
			if($min) {
				if($this->amount_transfer < $min) {
					$this->addError($attribute, Yii::t('main', 'min_deposit').' '.$min.' '.strtoupper($this->type));
				}
			}
		}
	}
}
